#define _CRT_SECURE_NO_WARNINGS 1
#include"stack.h"

void test() {
	ST stack = { 0 };
	StackInit(&stack);
	StackPush(&stack, 1);
	/*int ret = StackEmpty(&stack);*/
	StackPop(&stack);
	StackPush(&stack, 2);
	StackPop(&stack);
	/*StackPop(&stack);*/
}

void test2() {
	ST stack = { 0 };
	StackInit(&stack);
	StackPush(&stack, 1);
	/*int ret = StackEmpty(&stack);*/
	/*StackPop(&stack);*/
	StackPush(&stack, 2);
	StackPush(&stack, 3);
	StackPush(&stack, 4);
	StackPush(&stack, 5);
	/*while (stack.top) {
		StackTop(&stack);
		StackPop(&stack);
	}*/
	/*int size=StackSize(&stack);*/
	StackDestroy(&stack);
}

bool isValid(char* s) {
    ST stack = { 0 };
    StackInit(&stack);
    int n = strlen(s);
    if (n % 2 != 0 || n == 0) return false;
    int i = 0;
    for (i = 0; i < n; i++) {
        if (s[i] == '(' ||
            s[i] == '[' ||
            s[i] == '{') {
            StackPush(&stack, s[i]);
        }
        else {
            int ret = StackEmpty(&stack);
            if (ret != 0) return false;
            char x = StackPop(&stack);
            if (s[i] == ')') {
                if (x != '(') return false;
            }
            else if (s[i] == ']') {
                if (x != '[') return false;
            }
            else if (s[i] == '}') {
                if (x != '{') return false;
            }
        }
    }
    int ret = StackEmpty(&stack);
    StackDestroy(&stack);
    if (ret == 0) return false;
    else return true;
}


int main() {
    char c[] = "()";
    isValid(c);
}